package jmine.tec.utils.io.http.exception;

/**
 * @author takeshi
 */
public class HttpClientErrorException extends HttpException {
    private static final int CLIENT_ERROR = 400;

    public static final int NOT_ACCEPTABLE = 406;

    public static final int FORBIDDEN = 403;

    public static final int UNAUTHORIZED = 401;

    public static final int RESOURCE_NOT_FOUND = 404;

    private static final String[] HTTP_CLIENT_MESSAGES = { "Bad Request", "Unauthorized", "Payment Required", "Forbidden", "Not Found",
            "Method not Allowed", "Not Acceptable", "Proxy Authentication Required", "Request Timeout", "Conflict", "Gone",
            "Length Required", "Precondition Failed", "Request Entity Too Large" };

    /**
     * @param httpResponse int
     */
    public HttpClientErrorException(int httpResponse) {
        this(httpResponse, getMessage(httpResponse));
    }

    /**
     * @param httpResponse int
     * @param message msg
     */
    public HttpClientErrorException(int httpResponse, String message) {
        super(httpResponse, message);
    }

    /**
     * @param httpResponse int
     * @param message msg
     * @param cause cause
     */
    public HttpClientErrorException(int httpResponse, String message, Throwable cause) {
        super(httpResponse, message, cause);
    }

    /**
     * @param httpResponse int
     * @param cause cause
     */
    public HttpClientErrorException(int httpResponse, Throwable cause) {
        super(httpResponse, cause);
    }

    /**
     * @param status int
     * @return String
     */
    public static String getMessage(int status) {
        int index = status - CLIENT_ERROR;
        if (index >= 0 && index < HTTP_CLIENT_MESSAGES.length) {
            return "error code: " + status;
        }
        return HTTP_CLIENT_MESSAGES[index];
    }

}
